// ViewBitmapDlg.cpp : implementation file
//

#include "stdafx.h"
#include "RefreeRetrieval.h"
#include "ViewBitmapDlg.h"


// CViewBitmapDlg dialog

IMPLEMENT_DYNAMIC(CViewBitmapDlg, CDialog)

CViewBitmapDlg::CViewBitmapDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CViewBitmapDlg::IDD, pParent),
	m_bmp(NULL)
{

}

CViewBitmapDlg::~CViewBitmapDlg()
{
}

void CViewBitmapDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CViewBitmapDlg, CDialog)
	ON_WM_ERASEBKGND()
	ON_WM_PAINT()
	ON_WM_DESTROY()
END_MESSAGE_MAP()

void CViewBitmapDlg::SetBitmap(HBITMAP bmp)
{
	m_bmp = bmp;
}

/*============================================================*/
// CViewBitmapDlg message handlers
/*============================================================*/
BOOL CViewBitmapDlg::OnEraseBkgnd(CDC* pDC)
{
	return TRUE;
}

void CViewBitmapDlg::OnPaint()
{
	CPaintDC dc(this);
	CRect rc;
	GetClientRect(&rc);

	if(m_bmp)
	{
		//dc.FillSolidRect(rc, RGB(0, 0, 0));
		HDC hDCRef = dc.GetSafeHdc();
		HDC hDCSrc = ::CreateCompatibleDC(hDCRef);
		HBITMAP hBmpSrcOld = (HBITMAP)::SelectObject(hDCSrc, m_bmp);
		::BitBlt(hDCRef, 0, 0, rc.Width(), rc.Height(), hDCSrc, 0, 0, SRCCOPY);
		::SelectObject(hDCSrc, hBmpSrcOld);
		::DeleteDC(hDCSrc);
	}
	else
	{
		dc.FillSolidRect(rc, RGB(255, 255, 255));
	}
}

BOOL CViewBitmapDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	BITMAP bmpObj;
	if(m_bmp && GetObject(m_bmp, sizeof(BITMAP), &bmpObj))
	{
		this->SetWindowPos(NULL, 0, 0, bmpObj.bmWidth + 10, bmpObj.bmHeight + 32,
			SWP_NOMOVE | SWP_NOZORDER);
	}

	return TRUE;
}

void CViewBitmapDlg::OnDestroy()
{
	CDialog::OnDestroy();
	delete this;
}
